package com.xebest.web.controller.purchase;  

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.junit.Test;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONObject;
import com.xebest.web.XeVenBaseTest;
import com.xebest.web.form.XeVenPurchForm;
import com.xebest.web.form.XeVenPurchProductForm;

/**  
 * @desc: 采购相关
 * @author: 李书峰
 * @createTime: 2017年6月23日 下午2:01:05  
 * @history:  
 * @version: v1.0    
 */
public class XeVenPurchController extends XeVenBaseTest{

	private static String URL_PREFIX = "http://localhost/purch/";
	
	/**
	 * 保存采购单
	 * @author: 李书峰
	 * @createTime: 2017年6月23日 下午2:14:30  
	 * @history:   void
	 */
	@Test
	public void insertPurch() {
		try{
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			form.setSupplierName("测试");
			form.setSupplierMobile("1234");
			form.setSupplierPhone("456");
			form.setStoreId("111");
			form.setFrontMoney(new BigDecimal(1111));
			form.setPrintStatus(1);
			form.setExpectedArrivalDate("2017-07-29 00:01:02");
			form.setFinanceExamineRemark("财务审核备注");
			form.setPurchExamineRemark("采购备注");
			form.setPurchStatus(1);
			form.setPurchType(1);
			form.setRemark("备注");
			form.setVersion(0);
			form.setSignDate("2017-07-27 00:01:02");
			//form.setSettleDate(settleDate);
			form.setSettlementMethod(1);
			//form.setSettleOrder(settleOrder);
			form.setSupplierCode("12345");
			form.setPurchAmount(new BigDecimal(2222));
			List<XeVenPurchProductForm> purchProductList = new ArrayList<XeVenPurchProductForm>();
			for( int i=0 ; i<2 ; i++){
				XeVenPurchProductForm product = new XeVenPurchProductForm();
				product.setBuyPrice(new BigDecimal(i));
				product.setProName("商品名称"+i);
				product.setProUnit("计量单位");
				product.setSpecName("规格名称");
				product.setPriceType(1);
				product.setBuyPrice(new BigDecimal(999));
				product.setProNum(new BigDecimal(888));
				product.setProAmount(new BigDecimal(4444));
				product.setRemark("商品备注");
				purchProductList.add(product);
			}
			form.setPurchProductList(purchProductList);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/insertPurch", form, String.class);
			assertSucces(retMsg);
		}catch(Exception e) { 
			e.printStackTrace();
		}
	}
	
	/**
	 * 查询采购单列表
	 * @author: 李书峰
	 * @createTime: 2017年6月23日 下午2:17:04  
	 * @history:   void
	 */
	@Test
	public void queryPurchList(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			form.setSearchText("");
			form.setSearchType(1);
			form.setSearchTimeType(1);
			form.setSearchTimeStart("");
			form.setSearchTimeEnd("");
			form.setPageNum(1);
			form.setPageSize(10);
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryPurchList", form, String.class);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 采购收货入库列表
	 * @author: 李书峰
	 * @createTime: 2017年6月23日 下午2:17:04  
	 * @history:   void
	 *//*
	@Test
	public void queryReceiptList(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setSearchText("赵");
//			form.setSignDateStart(date);
//			form.setSignDateEnd(date);
//			form.setCompleteDateStart(date);
//			form.setCompleteDateEnd(date);
//			form.setExpectedArrivalDateStart(date);
//			form.setExpectedArrivalDateEnd(date);
			form.setPageNum(1);
			form.setPageSize(10);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryReceiptList", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 财务审核采购单列表
	 * @author: 李书峰
	 * @createTime: 2017年6月23日 下午2:17:04  
	 * @history:   void
	 *//*
	@Test
	public void queryFinanceCheckList(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setSearchText("赵");
//			form.setCheckStatus(1);
//			form.setPurchStatus(1);
//			form.setPurchType(1);
//			form.setSignDateStart(date);
//			form.setSignDateEnd(date);
//			form.setCompleteDateStart(date);
//			form.setCompleteDateEnd(date);
//			form.setExpectedArrivalDateStart(date);
//			form.setExpectedArrivalDateEnd(date);
			form.setPageNum(1);
			form.setPageSize(10);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryFinanceCheckList", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 采购单详情
	 * @author: 李书峰
	 * @createTime: 2017年6月21日 下午4:06:04  
	 * @history:  
	 * @param purchCode
	 * @return BaseResponse
	 *//*
	@Test
	public void queryPurchDetail(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setPurchOrder("P2d1533a99d5b41d");
			form.setVersion(0);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryPurchDetail", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 采购单商品列表
	 * @author: 李书峰
	 * @createTime: 2017年6月22日 上午10:31:50  
	 * @history:  
	 * @param purchCode
	 * @return BaseResponse
	 */
	@Test
	public void queryPurchProducts(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setPurchOrder("P2d1533a99d5b41d");
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/queryPurchProducts", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 采购审核采购单
	 * @author: 李书峰
	 * @createTime: 2017年6月22日 上午10:33:39  
	 * @history:  
	 * @param form
	 * @return BaseResponse
	 *//*
	@Test
	public void purchCheck(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setCheckStatus(3);
			form.setPurchOrder("P2d1533a99d5b41d");
			form.setPurchExamineRemark("采审备注");
			form.setVersion(0);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/purchCheck", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 财务审核采购单
	 * @author: 李书峰
	 * @createTime: 2017年6月22日 上午10:33:39  
	 * @history:  
	 * @param form
	 * @return BaseResponse
	 *//*
	@Test
	public void financeCheck(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setCheckStatus(4);
			form.setPurchOrder("P2d1533a99d5b41d");
			form.setFinanceExamineRemark("财审备注");
			form.setVersion(0);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/financeCheck", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 编辑采购单
	 * @author: 李书峰
	 * @createTime: 2017年6月22日 上午10:33:51  
	 * @history:  
	 * @param form
	 * @return BaseResponse
	 *//*
	@Test
	public void updatePurch(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setPurchOrder("P2d1533a99d5b41d");
			form.setVersion(0);
			List<XeVenPurchProductForm> purchProductList = new ArrayList<XeVenPurchProductForm>();
			for( int i=2 ; i<4 ; i++){
				XeVenPurchProductForm product = new XeVenPurchProductForm();
				product.setBuyPrice(new BigDecimal(i));
				product.setProSku("SKU"+uuid);
				product.setProName("商品名称"+i);
				product.setProUnit("计量单位");
				product.setPurchOrder("PURCHORDER"+uuid.substring(10));
				product.setSpecName("规格名称");
				product.setPriceType(1);
				product.setBuyPrice(new BigDecimal(111));
				product.setProNum(new BigDecimal(777));
				product.setProAmount(new BigDecimal(3333));
				product.setRemark("商品备注");
				purchProductList.add(product);
			}
			form.setPurchProductList(purchProductList);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/updatePurch", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 确认完成采购单
	 * @author: 李书峰
	 * @createTime: 2017年6月22日 上午10:33:51  
	 * @history:  
	 * @param form
	 * @return BaseResponse
	 *//*
	@Test
	public void finishPurch(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setPurchOrder("P2d1533a99d5b41d");
			form.setVersion(0);
			form.setPurchStatus(4);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/savePurch", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 确认收货入库
	 * @author: 李书峰
	 * @createTime: 2017年6月22日 上午10:33:51  
	 * @history:  
	 * @param form
	 * @return BaseResponse
	 *//*
	@Test
	public void goodsReceipt(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setPurchOrder("P2d1533a99d5b41d");
			form.setVersion(0);
			form.setPurchStatus(3);
			form.setPurchType(2);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/savePurch", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	*//**
	 * 删除采购单
	 * @author: 李书峰
	 * @createTime: 2017年6月22日 上午10:33:51  
	 * @history:  
	 * @param form
	 * @return BaseResponse
	 *//*
	@Test
	public void delPurch(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			Date date = new Date();
			String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
			form.setPurchOrder("P2d1533a99d5b41d");
			form.setVersion(0);
			String retMsg = restTemplate.postForObject(URL_PREFIX + "/delPurch", form, String.class);
			System.out.println(retMsg);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/
	
	/*public static void main(String args[]){
		XeVenPurchForm form = new XeVenPurchForm();
		Date date = new Date();
		String uuid = (UUID.randomUUID().toString().replace("-", "")).substring(0, 15);
		form.setUserCode("SH170712925781");
		
		List<XeVenPurchForm> list = null;
		if( null == list || list.size() == 0){
			System.out.println("1111");
		}
		
*//**     采购单新建编辑和删除      
 * 		
		form.setId(1);
		form.setSupplierCode("s"+uuid);
		form.setSupplierName("赵钱孙李");
		form.setSupplierMobile("1234");
		form.setSupplierPhone("456");
		form.setStoreId("111");
		form.setFrontMoney(new BigDecimal(1111));
		form.setCheckStatus(1);
		form.setCreateDate(date);
		form.setModifyDate(date);
		form.setPrintStatus(1);
		form.setCreateUser("c"+uuid);
		form.setModifyUser("m"+uuid);
		form.setDelFlag(1);
		form.setExpectedArrivalDate(date);
		form.setFinanceExamineDate(date);
		form.setFinanceExamineRemark("财务审核备注");
		form.setPayDate(date);
		form.setPurchExamineDate(date);
		form.setPurchExamineRemark("采购备注");
//		form.setPurchOrder("p"+uuid);
		form.setPurchStatus(1);
		form.setPurchType(1);
		form.setRemark("备注");
		form.setUserCode("c"+uuid);
		form.setVersion(0);
		form.setSignDate(date);
		//form.setSettleDate(settleDate);
		form.setSettlementMethod(1);
		//form.setSettleOrder(settleOrder);
		form.setUserCode("u"+uuid);
		List<XeVenPurchProductForm> purchProductList = new ArrayList<XeVenPurchProductForm>();
		XeVenPurchProductForm product = new XeVenPurchProductForm();
		product.setId(1);
		product.setBuyPrice(new BigDecimal(123));
		product.setProSku("sku1"+uuid);
		product.setProName("商品名称1");
		product.setProUnit("计量单位");
		product.setPurchOrder("p"+uuid);
		product.setSpecName("规格名称");
		product.setPriceType(1);
		product.setBuyPrice(new BigDecimal(999));
		product.setProNum(new BigDecimal(888));
		product.setProAmount(new BigDecimal(4444));
		product.setRemark("商品备注");
		purchProductList.add(product);
		XeVenPurchProductForm product1 = new XeVenPurchProductForm();
//		product1.setId(2);
		product1.setBuyPrice(new BigDecimal(123));
		product1.setProSku("sku3"+uuid);
		product1.setProName("商品名称3");
		product1.setProUnit("计量单位");
		product1.setPurchOrder("P"+uuid);
		product1.setSpecName("规格名称");
		product1.setPriceType(1);
		product1.setBuyPrice(new BigDecimal(999));
		product1.setProNum(new BigDecimal(888));
		product1.setProAmount(new BigDecimal(4444));
		purchProductList.add(product1);
		form.setPurchProductList(purchProductList);
		product.setRemark("商品备注");*//*
		
		*//**
		 * 审核
		form.setCheckStatus(2);
		form.setPurchOrder("P2d1533a99d5b41d");
		form.setUserCode("m"+uuid);
		form.setPurchExamineRemark("采审备注");
		form.setFinanceExamineRemark("财审备注");
		form.setType(1);
		form.setVersion(0);*//*
		
		*//**
		 * 确认采购单
		form.setPurchOrder("P2d1533a99d5b41d");
		form.setUserCode("m"+uuid);
		form.setVersion(0);
		form.setPurchStatus(4);*//*
		
		*//**采购单列表
		 * form.setSearchText("单号或供货商编号或供货商用户名");
		form.setCheckStatus(1);
		form.setPurchStatus(1);
		form.setPurchType(1);
		form.setSignDateStart(date);
		form.setSignDateEnd(date);
		form.setCompleteDateStart(date);
		form.setCompleteDateEnd(date);
		form.setExpectedArrivalDateStart(date);
		form.setExpectedArrivalDateEnd(date);
		form.setPageNum(1);
		form.setPageSize(10);
		*//*
		
		*//**采购详情和采购商品列表
		form.setPurchOrder("P2d1533a99d5b41d");
		form.setUserCode("mc023f29ce9cd4b8");*//*
		//System.out.println(JSONObject.toJSON(form).toString());
		
		
	}
	*/
	
	@Test
	public void queryPurchListYSL(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			XeVenPurchForm form = new XeVenPurchForm();
			form.setSearchText("CG18061575392138");
			form.setSearchType(1);
			//form.setSearchTimeType(1);
			form.setPageNum(1);
			form.setPageSize(10);
			//form.setSearchTimeStart("2011-09-25 17:39:47");
			System.out.println(JSONObject.toJSON(form).toString());
			String retMsg = restTemplate.postForObject("http://127.0.0.1:8081/restApi/purchManage/queryPurchList", form, String.class);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void queryPurchDetailYSL(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			
			Map<String, String> param = new HashMap<String , String>() ;
			param.put("purchOrder", "CG1807588932240") ;
			param.put("version", "16") ;
			/*param.put("purchOrder", "CG1807594842247") ;
			param.put("version", "5") ;*/
			String retMsg = restTemplate.postForObject("http://127.0.0.1/restApi/purchManage/queryPurchDetail", param, String.class);
			System.out.println(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void queryPurchProductsYSL(){
		try {
			RestTemplate restTemplate = new RestTemplate();
			
			Map<String, String> param = new HashMap<String , String>() ;
			param.put("purchOrder", "CG17092254250908") ;
			param.put("purchType", "1") ;
			String retMsg = restTemplate.postForObject("http://127.0.0.1/restApi/purchManage/queryPurchProducts", param, String.class);
			assertSucces(retMsg);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
  
